package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsAssessArchive;
import com.ruoyi.system.domain.news.query.NewsAssessArchiveQuery;
import com.ruoyi.system.domain.news.vo.NewsAssessArchiveVo;
import com.ruoyi.system.service.news.NewsAssessArchiveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsAssessArchive")
@Api(value = "newsAssessArchiveApiController", tags  = "定级备案Api")
public class NewsAssessArchiveApiController extends BaseController {

	@Resource
	private NewsAssessArchiveService newsAssessArchiveService;

	@ApiOperation(value = "获取单个定级备案信息", notes = "获取单个定级备案信息")
	@GetMapping("/getById")
	public R<NewsAssessArchive> getById(@RequestParam(value = "id") Long id) {
		NewsAssessArchiveQuery newsAssessArchiveQuery = new NewsAssessArchiveQuery();
		newsAssessArchiveQuery.setId(id);
		List<NewsAssessArchiveVo> newsAssessArchiveList = newsAssessArchiveService.getNewsAssessArchiveList(newsAssessArchiveQuery);
		if (newsAssessArchiveList!=null&&newsAssessArchiveList.size()>0) {
			return R.ok(newsAssessArchiveList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取定级备案信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsAssessArchiveVo>> list(@RequestBody NewsAssessArchiveQuery newsAssessArchiveQuery) {
        newsAssessArchiveQuery.setIsEnable("1");
		List<NewsAssessArchiveVo> newsAssessArchiveList = newsAssessArchiveService.getNewsAssessArchiveList(newsAssessArchiveQuery);
		return R.ok(new PageInfo<>(newsAssessArchiveList));
	}
}
